#include <iostream>
#include <string>
#include <cstring>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <stdio.h>
#include <string.h>
using namespace std;
#define _SKIP_LINE_ do{scanf("%*[^\n]"); getc(stdin);}while(0)

/* main
 *  * */
int main() {
	unsigned short test_cases  = 0;
	unsigned short relatives = 0;
	unsigned short streets[501];
	cin >> test_cases;
	while(test_cases-- > 0 && cin.eof() != true) {
		cin >> relatives;
		for(unsigned short i=0; i < relatives; ++i) {
			cin >> streets[i];
		}
		nth_element(streets, streets+(relatives/2), streets+relatives); 
		unsigned short key = streets[relatives/2];
		unsigned long sum = 0;
		for(short i = 0; i < relatives; ++i) {
			sum += abs(key - streets[i]);
		}
		cout << sum << endl;
	}
	return 0;
}
